package com.sskj.mine.http;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.request.GetRequest;
import com.lzy.okgo.request.PostRequest;
import com.sskj.common.base.App;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.LanguageUtil;
import com.sskj.common.util.MD5Util;
import com.sskj.lib.bean.AppVersionBean;
import com.sskj.lib.bean.PageBean;
import com.sskj.lib.util.APKVersionCodeUtils;
import com.sskj.mine.bean.CqtfBean;
import com.sskj.mine.bean.DetailListBean;
import com.sskj.mine.bean.FriendBean;
import com.sskj.mine.bean.LoginBean;
import com.sskj.mine.bean.OtherAssetBean;
import com.sskj.mine.bean.RecordsBean;
import com.sskj.mine.bean.SpreadBean;
import com.sskj.mine.bean.SpreadTitleBean;
import com.sskj.mine.bean.WalletXieyiBean;
import com.sskj.mine.bean.WithdrawSxf;
import com.sskj.mine.bean.XieyiBean;

import java.util.Locale;
import java.util.concurrent.Executor;

/**
 * 作者 :吕志豪
 * 简书：https://www.jianshu.com/u/6e525b929aac
 * github：https://github.com/lvzhihao100
 * 描述：
 * 创建时间：2018-10-15 14:08
 */
public class HttpService {

    /**
     * 充值/提币记录
     *
     * @param type recharge 充值 cash 提币
     * @return
     */
    public GetRequest<HttpData<PageBean<RecordsBean>>> getAssetRecord(String type, String p, String size) {
        return OkGo.<HttpData<PageBean<RecordsBean>>>get(HttpConfig.BASE_URL + "/Home/user/record")
                .params("type", type)
                .params("p", p)
                .params("size", size)
                ;
    }

    public PostRequest<HttpData> cancelTibi(String id) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + "/Home/Users/cancle_tibi")
                .params("cash_id", id);
    }

    public PostRequest<HttpData<PageBean<OtherAssetBean>>> getOtherAssetRecord(String p, String size) {
        return OkGo.<HttpData<PageBean<OtherAssetBean>>>post(HttpConfig.BASE_URL + HttpConfig.MINE_CQTF_RECORD)
                .params("p", p)
                .params("size", size);
    }

    public PostRequest<HttpData> withdraw(String num, String code, String address) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.WITHDRAW)
                .params("num", num)
                .params("code", code)
                .params("qianbao_url", address);
    }

    // 获取手续费
    public PostRequest<HttpData<WithdrawSxf>> getSxf() {
        return OkGo.<HttpData<WithdrawSxf>>post(HttpConfig.BASE_URL + HttpConfig.WITHDRAW_SXF);
    }

    /**
     * 登录
     *
     * @param mobile 账号
     * @param opwd   密码
     * @return
     */
    public PostRequest<HttpData<LoginBean>> login(String mobile, String opwd) {
        return OkGo.<HttpData<LoginBean>>post(HttpConfig.BASE_URL + HttpConfig.LOGIN)
                .params("mobile", mobile)
                .params("opwd", MD5Util.getMd5Value(opwd));
    }

    /**
     * 指纹登录验证密码
     *
     * @param opwd 密码
     * @return
     */
    public PostRequest<HttpData<LoginBean>> checkFingerPwd(String opwd) {
        return OkGo.<HttpData<LoginBean>>post(HttpConfig.BASE_URL + HttpConfig.CHECK_FINGER_PWD)
                .params("opwd", opwd);
    }

    /**
     * 发送验证码（注册）
     *
     * @param mobile 手机号
     * @param type   1注册 （2 重置 3 安全验证 4 资金密码设置 5 提币）
     * @return
     */
    public GetRequest<HttpData> sendSms(String mobile, String type) {
        return OkGo.<HttpData>get(HttpConfig.BASE_URL + HttpConfig.GET_CODE)
                .params("mobile", mobile)
                .params("type", type);
    }

    /**
     * 注册
     *
     * @param mobile 手机号/邮箱号
     * @param code   验证码
     * @param opwd   密码
     * @param opwd1  重复密码
     * @param tjuser 推荐码/邀请码
     * @return
     */
    public PostRequest<HttpData> register(String mobile, String code, String opwd, String opwd1, String tjuser) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.MINE_REGISTER)
                .params("mobile", mobile)
                .params("code", code)
                .params("opwd", MD5Util.getMd5Value(opwd))
                .params("opwd1", MD5Util.getMd5Value(opwd1))
                .params("tjuser", tjuser);
    }


    /**
     * 重置登录密码
     *
     * @param mobile 手机号/邮箱号
     * @param opwd   密码
     * @param opwd1  确认登录密码
     * @param code   验证码
     * @return
     */
    public PostRequest<HttpData> resetLoginPwd(String mobile, String opwd, String opwd1, String code) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.RESET_LOGIN_PWD)
                .params("mobile", mobile)
                .params("opwd", MD5Util.getMd5Value(opwd))
                .params("opwd1", MD5Util.getMd5Value(opwd1))
                .params("code", code);
    }

    // 充值
    public PostRequest<HttpData<CqtfBean>> rechargeImg() {
        return OkGo.<HttpData<CqtfBean>>post(HttpConfig.BASE_URL + HttpConfig.MINE_CQTF_RECHARGE);
    }

    // 版本更新
    public PostRequest<HttpData<AppVersionBean>> getVersion() {
        return OkGo.<HttpData<AppVersionBean>>post(HttpConfig.BASE_URL + HttpConfig.VERSION)
                .params("version", APKVersionCodeUtils.getVerName(App.INSTANCE))
                .params("type", "1");
    }


    public PostRequest<HttpData<XieyiBean>> getXieyi() {
        return OkGo.<HttpData<XieyiBean>>post(HttpConfig.BASE_URL + HttpConfig.XIEYI)
                .params("lang", (LanguageUtil.getAppLocale(App.INSTANCE) == Locale.ENGLISH ? "en" : "zh"))
                ;
    }

    public PostRequest<HttpData<WalletXieyiBean>> getWalletXieyi() {
        return OkGo.<HttpData<WalletXieyiBean>>post(HttpConfig.BASE_URL + HttpConfig.WALLET_XIEYI)
                ;
    }

    public PostRequest<HttpData<SpreadTitleBean>> getSpreadTitle(String p, String size) {
        return OkGo.<HttpData<SpreadTitleBean>>post(HttpConfig.BASE_URL + HttpConfig.SPREAD_TITLE)
                ;
    }

    public PostRequest<HttpData<PageBean<FriendBean>>> getSpreadFriend(String p, String size) {
        return OkGo.<HttpData<PageBean<FriendBean>>>post(HttpConfig.BASE_URL + HttpConfig.SPREAD_TITLE)
                .params("p", p)
                .params("size", size)
                ;
    }

    public PostRequest<HttpData<PageBean<DetailListBean>>> getDetailList(String p, String size) {
        return OkGo.<HttpData<PageBean<DetailListBean>>>post(HttpConfig.BASE_URL + HttpConfig.DETAIL_LIST)
                .params("p", p)
                .params("size", size)
                ;
    }

    public PostRequest<HttpData<SpreadBean>> getSpreadData() {
        return OkGo.<HttpData<SpreadBean>>post(HttpConfig.BASE_URL + HttpConfig.SPREAD_DATA);

    }
}